{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2\n",
    "import os\n",
    "import time\n",
    "from IPython.display import clear_output\n",
    "from genetic_drawing import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#load the example image and set the generator for 100 stages with 20 generations each\n",
    "gen = GeneticDrawing('example.jpg', seed=time.time())\n",
    "out = gen.generate(100, 20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#load a custom mask and set a smaller brush size for finer details\n",
    "gen.sampling_mask = cv2.cvtColor(cv2.imread(\"mask.jpg\"), cv2.COLOR_BGR2GRAY)\n",
    "gen.brushesRange = [[0.05, 0.1], [0.1, 0.2]]\n",
    "#keep drawing on top of our previous result\n",
    "out = gen.generate(40, 30)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#save all the images from the image buffer\n",
    "if not os.path.exists('out'):\n",
    "    os.mkdir(\"out\")\n",
    "for i in range(len(gen.imgBuffer)):\n",
    "    cv2.imwrite(os.path.join(\"out\", f\"{i:06d}.png\"), gen.imgBuffer[i])\n",
    "#if you want to save only last image, run below\n",
    "# cv2.imwrite(\"out/final.png', out)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
